package mr.aurelien.blackboard.model;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Color;

public class Stroke {
	/*
	 * Contains all the point of the stroke
	 */
	private List<Point> points = new ArrayList<Point>(); 
	/*
	 * Indicates the color of the stroke
	 */
	public int color = Color.BLACK;
	/*
	 * Width of the stroke
	 */
	public int width = 5;
	
	@Override
    public String toString() {
        return "Stroke with" + points.size() + "points" ;
    } 
	/*
	 * Indicates if stroke contains points
	 */
	public boolean isEmpty()
	{
		return points.isEmpty();
	}
	/*
	 * Add a point to the current stroke
	 */
	public void AddPoint(float x, float y, long delay)
	{
		points.add(new Point(x,y,delay));
	}
	/*
	 * Give the number of points
	 */
	public int getPointSize() {
		return points.size();
	}
	/*
	 * Get a point at given index
	 */
	public Point getPoint(int index) {
		try{
			return points.get(index);
		}
		catch(Exception e)
		{
			return null;
		}
	}
	/*
	 * Export object to JSON format. Manual implementation
	 */
	@Deprecated
	public String toJSON(){
		String json = "";
		json += "{";
		json += "\"color\":\""+this.color+"\"";
		json += ",";
		json += "\"width\":\""+this.width+"\"";
		json += ",";
		json += "\"points\":[";
			for (int i=0 ; i< points.size() ; i++)
			{
				json += points.get(i).toJSON();
				// No coma after last object
				if(i!=(points.size()-1))
					json += ",";
			}
			json += "]";
		json += "}";
		return json;
	}
}
